package com.sunyard.utils;

import com.sunyard.utils.manage.DateUtil;

import java.util.Date;
import java.util.UUID;

/**
 * @author k3887
 * @Program PrimaryKeyUtil
 * @Description TODO
 * @Date 2018/11/30
 * @Version V1.0
 */
public class PrimaryKeyUtil {
    /**
     * @return String
     * @throws
     * @Title getPrimaryKey
     * @Description 生成主键ID
     */
    public static String getPrimaryKey() {
        String first = DateUtil.getDateStr(DateUtil.YYYYMMDDHHMMSS, new Date());
        String thrid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        return first + thrid.substring(0, 32 - first.length());
    }

    /**
     * @param mid
     * @return String
     * @throws
     * @Title getPrimaryKey
     * @Description 生成主键ID
     */
    public static String getPrimaryKey(String mid) {
        String first = DateUtil.getDateStr(DateUtil.YYYYMMDDHHMMSS, new Date());
        String thrid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        mid = mid.substring(0, 2);
        return first + mid.toUpperCase() + thrid.substring(0, 32 - first.length() - mid.length());
    }

    /**
     * @param mid
     * @return String
     * @throws
     * @Title getPrimaryKey
     * @Description 生成主键ID 30位
     */
    public static String getPrimaryKeyOwner(String mid) {
        String first = DateUtil.getDateStr(DateUtil.YYYYMMDDHHMMSS, new Date());
        String thrid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        mid = mid.substring(0, 2);
        return first + mid.toUpperCase() + thrid.substring(0, 30 - first.length() - mid.length());
    }

    /**
     * 专为商户进件merchant_remark30位UUID字段使用
     */
    public static String getPrimaryKeyForAddMchnt(String mid) {
        String first = DateUtil.getDateStr(DateUtil.YYYYMMDDHHMMSS, new Date());
        String thrid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        mid = mid.substring(0, 2);
        return first + mid.toUpperCase() + thrid.substring(0, 30 - first.length() - mid.length());

    }

    /**
     * @return String
     * @throws
     * @Title getPrimaryKey
     * @Description 生成用户表主键ID 8位
     */
    public static String getPrimaryKeyOp() {
        String first = DateUtil.getDateStr(DateUtil.YYYY, new Date());
        String thrid = UUID.randomUUID().toString().toUpperCase().replace("-", "");
        return first + thrid.substring(0, 4);
    }

    //public static void main(String[] args) {
    //	String hf = getPrimaryKey("SH");
    //	System.out.println(hf);
    //}
}
